package org.coldlife.sim.display;

import java.awt.Graphics;
import java.util.List;

import javax.vecmath.Vector3d;

import org.coldlife.sim.grav.Particle;
import org.coldlife.sim.grav.World;

public class WorldDisplayPanel extends DrawPanel
{
	private static final long serialVersionUID = -6741619165256414493L;
	private World world;
	
	public WorldDisplayPanel(World world) 
	{
		super(15);
		this.world = world;
	}

	@Override
	protected void paintComponent(Graphics g) 
	{
		super.paintComponent(g);
		synchronized (world) 
		{
			if(getWorld() == null) return;
			
			List<? extends Particle> particles = getWorld().getParticles();
			for (Particle particle : particles) 
			{
				Vector3d pos = particle.getPosition();
				int size = (int)Math.max(1, pos.z);
				g.drawOval((int)pos.x-size/2, (int)pos.y-size/2, size, size);
			}
		}
	}

	public World getWorld() {
		return world;
	}

	public void setWorld(World world) {
		this.world = world;
	}
}
